﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Org.LyrcsoftFramework.Cloud.Core
{
    public class ServiceDescriptor
    {
        public Type ServiceType { get; }

        public Type ImplementationType { get; }

        public object ImplementationInstance { get; }

        public Func<IServiceProvider, object> ImplementationFactory { get; }

        private ServiceDescriptor(Type serviceType)
        {
            ServiceType = serviceType;
        }
        public ServiceDescriptor(Type serviceType, Func<object> factory)
           : this(serviceType)
        {
            if (serviceType == null)
            {
                throw new ArgumentNullException("serviceType");
            }

            if (factory == null)
            {
                throw new ArgumentNullException("factory");
            }
            ServiceFactory.RegisterService(serviceType, factory.Invoke());
        }
    }
}
